function load_image(data) {
    var str = '';
    for (var i = 0; i < data.info.length; i++) {
        var row = data.info[i];
        str +=
            '<div class="item" data-w="' + row.width + '" data-h="' + row.height + '">\n' +
            '  <a href="/picture/single/?pid=' + row.id + '">\n' +
            '    <img src="' + row.url + '" alt="">\n' +
            '  </a>\n' +
            '  <div>\n' +
            '    <div class="counts hide-xs hide-sm ">\n' +
            '      <em data-href="" class="ajax"><i class="iconfont icon-icon_like" style="pointer-events: none;"></i>\n' +
            '' + row.click_num + '</em>\n' +
            '      <em data-href="" class="ajax"><i class="iconfont icon-favorite"\n' +
            '  style="pointer-events: none;"></i> ' + row.star_num + '</em>\n' +
            '      <em data-location=""><i class="iconfont icon-speechbubble"></i> ' + row.parise_num + '</em>\n' +
            '    </div>\n' +
            '    <a href=""></a>\n' +
            '  </div>\n' +
            '</div>';
    }
    return str;
}

function others() {
    changeImage();
    $('.flex-images').flexImages({rowHeight: 275});
    // 显示点赞收藏数
    $(".item").hover(
        function (e) {
            e.currentTarget.children[1].style.opacity = 1;
        },
        function (j) {
            j.currentTarget.children[1].style.opacity = 0;
        });
}


function picture_star() {
    // 请求图片
    $.get('/user/user_star/', {
        'type': 1,
    }, function (data) {
        data = JSON.parse(data);
        // 处理异常
        if (data.status == 200) {
            var str = load_image(data);
            if (str == '') {
                str = '<div class="my_picture">\n' +
                    '                        <p>暂点赞无记录,快去为你稀饭的图片点赞吧</p>\n' +
                    '</div>'
            }
            $('.picture_star').append(str);
            others();
        } else {
        }
    });
};

function picture_parise() {
    // 请求图片
    $.get('/user/user_parise/', {
        'type': 1,
    }, function (data) {
        data = JSON.parse(data);
        // 处理异常
        if (data.status == 200) {
            var str = load_image(data);
            if (str == '') {
                str = '<div class="my_picture">\n' +
                    '                        <p>暂无收藏记录,快去收藏你稀饭的图片吧</p>\n' +
                    '</div>'
            }
            $('.picture_parise').append(str);
            others();
        } else {
        }
    });
}

//异步刷新下载记录
function download_show() {
    // 请求图片
    $.get('/user/user_download/', {}, function (data) {
        data = JSON.parse(data);
        console.log((data));
        // 处理异常
        if (data.status == 200) {
            var str = load_image(data);
            if (str == '') {
                str = '<div class="my_picture">\n' +
                    '                        <p>暂无下载记录,快去下载你稀饭的图片吧</p>\n' +
                    '</div>'
            }
            $('.picture_download').append(str);
            others();
        } else {
        }
    });
}